package controller;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import model.VO.CategoryPageVO;
import service.Impl.CategoryServiceImpl;
import util.ResultUtil;

import java.io.IOException;
@WebServlet("/admin/category/page")
public class CategoryPageController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CategoryServiceImpl service=new CategoryServiceImpl();
        int page= Integer.parseInt(req.getParameter("page"));
        int pageSize= Integer.parseInt(req.getParameter("pageSize"));
        String name=req.getParameter("name");
        Integer type= null;
        if(req.getParameter("type")!=null&& !req.getParameter("type").equals("")){
            type=Integer.parseInt(req.getParameter("type"));
        }

        CategoryPageVO vo=service.Page(page,pageSize,name,type);
        String json= ResultUtil.getJSON(vo);
        resp.getWriter().write(json);
    }
}
